use bincode;
use bincode::{config, Decode, Encode};
use log::info;

#[derive(Encode, Decode, PartialEq, Debug)]
struct Person {
    name: String,
    age: u8,
    hobbies: Vec<String>,
}

#[test]
fn main() {
    env_logger::init();
    // Create an instance of the struct
    let person = Person {
        name: "Alice".to_string(),
        age: 30,
        hobbies: vec!["reading".to_string(), "hiking".to_string()],
    };

    let config = config::standard();
    // Serialize the struct into a Vec<u8>
    let encoded: Vec<u8> = bincode::encode_to_vec(&person, config).unwrap();
    info!("Encoded: {:?}", encoded); // You'll see a compact byte array

    // Deserialize the Vec<u8> back into a Person struct
    let (decoded, len) = bincode::decode_from_slice(&encoded[..], config).unwrap();

    // Verify they are the same
    assert_eq!(person, decoded);
    info!("Successfully deserialized: {:?}", decoded);
}